/*
 *  Door.m
 *  pogostick
 *
 * There isn't much to the door. This is the thing that the pogostick
 * has to touch to get to the next level.
 *
 *  Created by chuck@kollar.com on 10/28/09.
 *  Copyright 2009 Charles P. Kollar All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#import "Door.h"


@implementation Door

@synthesize space;
@synthesize body;
@synthesize width;
@synthesize height;

-(id)initInSpace:(cpSpace *)sp toStaticBody:(cpBody *) __attribute__ ((unused)) sb position:(cpVect)p size:(cpVect)size {
    if (self = [super init]) {
        space = sp;
        width = size.x;
        height = size.y;
        
		cpVect verts[] = {
			cpv(-width/2.0f,-height/2.0f),	// bottom left
			cpv(-width/2.0f, height/2.0f),	// top left
			cpv( width/2.0f, height/2.0f),	// top right
			cpv( width/2.0f,-height/2.0f)	// lower right
		};
        body = cpBodyNew(10.0f, cpMomentForPoly(10.0f, (sizeof(verts)/sizeof(cpVect)), verts, cpvzero));
		body->p = p;
        
        // door frame...
		cpShape *shape = cpPolyShapeNew(body, (sizeof(verts)/sizeof(cpVect)), verts, cpvzero);
        cpSpaceAddStaticShape(space, shape);

        // door knob...
        shape = cpCircleShapeNew(body, width*0.1f, cpv(width*0.3f, 0.0f));
        cpSpaceAddStaticShape(space, shape);
        
    }
    return self;
}

-(void) dealloc {
	[super dealloc];
}

@end
